#include "facecat/stdafx.h"
#include "AndroidPaint.h"
#include "AndroidHost.h"
#include <jni.h>

lstring NativeCmd::commandsToStr(ArrayList<NativeCmd> *cmds) {
    String str = L"";
    int cmdsSize = cmds->size();
    String countStr = FCTran::intToStr(cmdsSize);
    str += FCTran::intToStr((int)countStr.length()) + L"," + countStr;
    for(int i = 0; i < cmdsSize; i++){
        NativeCmd pc = cmds->get(i);
        String sCmd = pc.cmd;
        str += FCTran::intToStr((int)sCmd.length()) + L"," + sCmd;
        int pointsSize = pc.points.size();
        String pointsSizeStr = FCTran::intToStr(pointsSize);
        str += FCTran::intToStr((int)pointsSizeStr.length()) + L"," + pointsSizeStr;
        for(int j = 0; j < pointsSize; j++){
            int pX = pc.points.get(j).x;
            int pY = pc.points.get(j).y;
            String pxStr = FCTran::intToStr(pX);
            str += FCTran::intToStr((int)pxStr.length()) + L"," + pxStr;
            String pyStr = FCTran::intToStr(pY);
            str += FCTran::intToStr((int)pyStr.length()) + L"," + pyStr;
        }
        int pointfsSize = pc.pointfs.size();
        String pointfsSizeStr = FCTran::intToStr(pointfsSize);
        str += FCTran::intToStr((int)pointfsSizeStr.length()) + L"," + pointfsSizeStr;
        for(int j = 0; j < pointfsSize; j++){
            float pX = pc.pointfs.get(j).x;
            float pY = pc.pointfs.get(j).y;
            String pxStr = FCTran::floatToStr(pX);
            str += FCTran::intToStr((int)pxStr.length()) + L"," + pxStr;
            String pyStr = FCTran::floatToStr(pY);
            str += FCTran::intToStr((int)pyStr.length()) + L"," + pyStr;
        }
        int colorsSize = pc.colors.size();
        String colorsSizeStr = FCTran::intToStr(colorsSize);
        str += FCTran::intToStr((int)colorsSizeStr.length()) + L"," + colorsSizeStr;
        for(int j = 0; j < colorsSize; j++){
            Long color = pc.colors.get(j);
            String colorStr = FCTran::longToStr(color);
            str += FCTran::intToStr((int)colorStr.length()) + L"," + colorStr;
        }
        int textsSize = pc.texts.size();
        String textsSizeStr = FCTran::intToStr(textsSize);
        str += FCTran::intToStr((int)textsSizeStr.length()) + L"," + textsSizeStr;
        for(int j = 0; j < textsSize; j++){
            String text = pc.texts.get(j);
            String sText = text;
            str += FCTran::intToStr((int)sText.length()) + L"," + sText;
        }
        int rectsSize = pc.rects.size();
        String rectsSizeStr = FCTran::intToStr(rectsSize);
        str += FCTran::intToStr((int)rectsSizeStr.length()) + L"," + rectsSizeStr;
        for(int j = 0; j < rectsSize; j++){
            int pLeft = pc.rects.get(j).left;
            int pTop = pc.rects.get(j).top;
            int pRight = pc.rects.get(j).right;
            int pBottom = pc.rects.get(j).bottom;
            String pLeftStr = FCTran::intToStr(pLeft);
            str += FCTran::intToStr((int)pLeftStr.length()) + L"," + pLeftStr;
            String pTopStr = FCTran::intToStr(pTop);
            str += FCTran::intToStr((int)pTopStr.length()) + L"," + pTopStr;
            String pRightStr = FCTran::intToStr(pRight);
            str += FCTran::intToStr((int)pRightStr.length()) + L"," + pRightStr;
            String pBottmStr = FCTran::intToStr(pBottom);
            str += FCTran::intToStr((int)pBottmStr.length()) + L"," + pBottmStr;
        }
        int rectfsSize = pc.rectfs.size();
        String rectfsSizeStr = FCTran::intToStr(rectfsSize);
        str += FCTran::intToStr((int)rectfsSizeStr.length()) + L"," + rectfsSizeStr;
        for(int j = 0; j < rectfsSize; j++){
            float pLeft = pc.rectfs.get(j).left;
            float pTop = pc.rectfs.get(j).top;
            float pRight = pc.rectfs.get(j).right;
            float pBottom = pc.rectfs.get(j).bottom;
            String pLeftStr = FCTran::floatToStr(pLeft);
            str += FCTran::intToStr((int)pLeftStr.length()) + L"," + pLeftStr;
            String pTopStr = FCTran::floatToStr(pTop);
            str += FCTran::intToStr((int)pTopStr.length()) + L"," + pTopStr;
            String pRightStr = FCTran::floatToStr(pRight);
            str += FCTran::intToStr((int)pRightStr.length()) + L"," + pRightStr;
            String pBottmStr = FCTran::floatToStr(pBottom);
            str += FCTran::intToStr((int)pBottmStr.length()) + L"," + pBottmStr;
        }
        int valuesSize = pc.values.size();
        String valuesSizeStr = FCTran::intToStr(valuesSize);
        str += FCTran::intToStr((int)valuesSizeStr.length()) + L"," + valuesSizeStr;
        for(int j = 0; j < valuesSize; j++){
            double value = pc.values.get(j);
            String valueStr = FCTran::doubleToStr(value);
            str += FCTran::intToStr((int)valueStr.length()) + L"," + valueStr;
        }
    }
    return FCTran::StringTostring(str);
}

AndroidPaint::AndroidPaint(){
    m_myColor = new MyColor;
    m_clipRect.left = 0;
    m_clipRect.top = 0;
    m_clipRect.right = 0;
    m_clipRect.bottom = 0;
    m_isClip = false;
    m_offsetX = 0;
    m_offsetY = 0;
    m_opacity = 1;
    m_pRect.left = 0;
    m_pRect.top = 0;
    m_pRect.right = 0;
    m_pRect.bottom = 0;
    m_scaleFactorX = 1;
    m_scaleFactorY = 1;
    m_wRect.left = 0;
    m_wRect.top = 0;
    m_wRect.right = 0;
    m_wRect.bottom = 0;
    m_native = 0;
}

AndroidPaint::~AndroidPaint(){
    clearCaches();
    if(m_myColor){
        delete m_myColor;
        m_myColor = 0;
    }
    m_native = 0;
}

void AndroidPaint::addArc(const FCRect& rect, float startAngle, float sweepAngle){
    NativeCmd nc;
    nc.cmd = L"addArc";
    nc.rects.add(rect);
    nc.values.add(startAngle);
    nc.values.add(sweepAngle);
    m_commands.add(nc);
}

void AndroidPaint::addBezier(FCPoint *apt, int cpt){
    NativeCmd nc;
    nc.cmd = L"addBezier";
    for(int i = 0; i < cpt; i++){
        nc.points.add(apt[i]);
    }
    m_commands.add(nc);
}

void AndroidPaint::addCurve(FCPoint *apt, int cpt){
    NativeCmd nc;
    nc.cmd = L"addCurve";
    for(int i = 0; i < cpt; i++){
        nc.points.add(apt[i]);
    }
    m_commands.add(nc);
}

void AndroidPaint::addEllipse(const FCRect& rect){
    NativeCmd nc;
    nc.cmd = L"addEllipse";
    nc.rects.add(rect);
    m_commands.add(nc);
}

void AndroidPaint::addLine(int x1, int y1, int x2, int y2){
    NativeCmd nc;
    nc.cmd = L"addLine";
    FCPoint point1 = {x1, y1};
    FCPoint point2 = {x2, y2};
    nc.points.add(point1);
    nc.points.add(point2);
    m_commands.add(nc);
}

void AndroidPaint::addRect(const FCRect& rect){
    NativeCmd nc;
    nc.cmd = L"addRect";
    nc.rects.add(rect);
    m_commands.add(nc);
}

void AndroidPaint::addPie(const FCRect& rect, float startAngle, float sweepAngle){
    NativeCmd nc;
    nc.cmd = L"addPie";
    nc.rects.add(rect);
    nc.values.add(startAngle);
    nc.values.add(sweepAngle);
    m_commands.add(nc);
}

void AndroidPaint::addText(String strText, FCFont *font, const FCRect& rect, int width){
    NativeCmd nc;
    nc.cmd = L"addText";
    nc.rects.add(rect);
    nc.texts.add(strText);
    nc.texts.add(FCTran::fontToStr(font));
    nc.rects.add(rect);
    nc.values.add(width);
    m_commands.add(nc);
}

void AndroidPaint::beginExport(const String& exportPath, const FCRect& rect){
}

void AndroidPaint::beginPaint(int hDC, const FCRect& wRect, const FCRect& pRect){
    m_isClip = false;
    m_opacity = 1;
    m_pRect = pRect;
    m_wRect = wRect;
    m_commands.clear();
}

void AndroidPaint::beginPath(){
    NativeCmd nc;
    nc.cmd = L"beginPath";
    m_commands.add(nc);
}

void AndroidPaint::clearCaches(){
    NativeCmd nc;
    nc.cmd = L"clearCaches";
    m_commands.add(nc);
}

void AndroidPaint::clipPath(){
    NativeCmd nc;
    nc.cmd = L"clipPath";
    m_commands.add(nc);
}	

void AndroidPaint::closeFigure(){
    NativeCmd nc;
    nc.cmd = L"closeFigure";
    m_commands.add(nc);
}

void AndroidPaint::closePath(){
    NativeCmd nc;
    nc.cmd = L"closePath";
    m_commands.add(nc);
}

void AndroidPaint::drawArc(Long dwPenColor, float width, int style, const FCRect& rect, float startAngle, float sweepAngle){
    if(dwPenColor == FCColor_None){
        return;
    }
    NativeCmd nc;
    nc.cmd = L"drawArc";
    nc.colors.add(getPaintColor(dwPenColor));
    nc.values.add(width);
    nc.values.add(style);
    nc.rects.add(rect);
    nc.values.add(startAngle);
    nc.values.add(sweepAngle);
    m_commands.add(nc);
}

void AndroidPaint::drawBezier(Long dwPenColor, float width, int style, FCPoint *apt, int cpt){
    if(dwPenColor == FCColor_None){
        return;
    }
    NativeCmd nc;
    nc.cmd = L"drawBezier";
    nc.colors.add(getPaintColor(dwPenColor));
    nc.values.add(width);
    nc.values.add(style);
    for(int i = 0; i < cpt; i++){
        nc.points.add(apt[i]);
    }
    m_commands.add(nc);
}

void AndroidPaint::drawCurve(Long dwPenColor, float width, int style, FCPoint *apt, int cpt){
    if(dwPenColor == FCColor_None){
        return;
    }
    NativeCmd nc;
    nc.cmd = L"drawCurve";
    nc.colors.add(getPaintColor(dwPenColor));
    nc.values.add(width);
    nc.values.add(style);
    for(int i = 0; i < cpt; i++){
        nc.points.add(apt[i]);
    }
    m_commands.add(nc);
}

void AndroidPaint::drawEllipse(Long dwPenColor, float width, int style, const FCRect& rect){
    if(dwPenColor == FCColor_None){
        return;
    }
    drawEllipse(dwPenColor, width, style, rect.left, rect.top, rect.right, rect.bottom);
}

void AndroidPaint::drawEllipse(Long dwPenColor, float width, int style, int left, int top, int right, int bottom){
    if(dwPenColor == FCColor_None){
        return;
    }
    FCRect rect = {left, top, right, bottom};
    NativeCmd nc;
    nc.cmd = L"drawEllipse";
    nc.colors.add(getPaintColor(dwPenColor));
    nc.values.add(width);
    nc.values.add(style);
    nc.rects.add(rect);
    m_commands.add(nc);
}

void AndroidPaint::drawImage(String imagePath, const FCRect& rect){
    NativeCmd nc;
    nc.cmd = L"drawImage";
    nc.rects.add(rect);
    m_commands.add(nc);
}

void AndroidPaint::drawLine(Long dwPenColor, float width, int style, const FCPoint& x, const FCPoint& y){
    if(dwPenColor == FCColor_None){
        return;
    }
    drawLine(dwPenColor, width, style, x.x, x.y, y.x, y.y);
}

void AndroidPaint::drawLine(Long dwPenColor, float width, int style, int x1, int y1, int x2, int y2){
    if(dwPenColor == FCColor_None){
        return;
    }
    NativeCmd nc;
    nc.cmd = L"drawLine";
    FCPoint point1 = {x1, y1};
    FCPoint point2 = {x2, y2};
    nc.colors.add(getPaintColor(dwPenColor));
    nc.values.add(width);
    nc.values.add(style);
    nc.points.add(point1);
    nc.points.add(point2);
    m_commands.add(nc);
}

void AndroidPaint::drawPath(Long dwPenColor, float width, int style){
    if(dwPenColor == FCColor_None){
        return;
    }
    NativeCmd nc;
    nc.cmd = L"drawPath";
    nc.colors.add(getPaintColor(dwPenColor));
    nc.values.add(width);
    nc.values.add(style);
    m_commands.add(nc);
}

void AndroidPaint::drawPie(Long dwPenColor, float width, int style, const FCRect& rect, float startAngle, float sweepAngle){
    if(dwPenColor == FCColor_None){
        return;
    }
    NativeCmd nc;
    nc.cmd = L"drawPie";
    nc.colors.add(getPaintColor(dwPenColor));
    nc.values.add(width);
    nc.values.add(style);
    nc.rects.add(rect);
    nc.values.add(startAngle);
    nc.values.add(sweepAngle);
    m_commands.add(nc);
}

void AndroidPaint::drawPolygon(Long dwPenColor, float width, int style, FCPoint *apt, int cpt){
    if(dwPenColor == FCColor_None){
        return;
    }
    NativeCmd nc;
    nc.cmd = L"drawPolygon";
    nc.colors.add(getPaintColor(dwPenColor));
    nc.values.add(width);
    nc.values.add(style);
    for(int i = 0; i < cpt; i++){
        nc.points.add(apt[i]);
    }
    m_commands.add(nc);
}

void AndroidPaint::drawPolyline(Long dwPenColor, float width, int style, FCPoint *apt, int cpt){
    if(dwPenColor == FCColor_None){
        return;
    }
    NativeCmd nc;
    nc.cmd = L"drawPolyline";
    nc.colors.add(getPaintColor(dwPenColor));
    nc.values.add(width);
    nc.values.add(style);
    for(int i = 0; i < cpt; i++){
        nc.points.add(apt[i]);
    }
    m_commands.add(nc);
}

void AndroidPaint::drawRect(Long dwPenColor, float width, int style, int left, int top, int right, int bottom){
    FCRect rect = {left, top, right, bottom};
    NativeCmd nc;
    nc.cmd = L"drawRect";
    nc.colors.add(getPaintColor(dwPenColor));
    nc.values.add(width);
    nc.values.add(style);
    nc.rects.add(rect);
    m_commands.add(nc);
}

void AndroidPaint::drawRect(Long dwPenColor, float width, int style, const FCRect& rect){
    drawRect(dwPenColor, width, style, rect.left, rect.top, rect.right, rect.bottom);
}

void AndroidPaint::drawRoundRect(Long dwPenColor, float width, int style, const FCRect& rect, int cornerRadius){
    if(dwPenColor == FCColor_None){
        return;
    }
    NativeCmd nc;
    nc.cmd = L"drawRoundRect";
    nc.colors.add(getPaintColor(dwPenColor));
    nc.values.add(width);
    nc.values.add(style);
    nc.rects.add(rect);
    nc.values.add(cornerRadius);
    m_commands.add(nc);
}

void AndroidPaint::drawText(String strText, Long dwPenColor, FCFont *font, const FCRect& rect, int width){
    if(dwPenColor == FCColor_None){
        return;
    }
    NativeCmd nc;
    nc.cmd = L"drawText";
    nc.colors.add(getPaintColor(dwPenColor));
    nc.texts.add(strText);
    nc.texts.add(FCTran::fontToStr(font));
    nc.rects.add(rect);
    nc.values.add(width);
    m_commands.add(nc);
}

void AndroidPaint::drawText(String strText, Long dwPenColor, FCFont *font, const FCRectF& rect, int width){
    FCRect rc = {(int)rect.left, (int)rect.top, (int)rect.right, (int)rect.bottom};
    drawText(strText, dwPenColor, font, rc, width);
}

void AndroidPaint::drawTextAutoEllipsis(String strText, Long dwPenColor, FCFont *font, const FCRect& rect){
    if(dwPenColor == FCColor_None){
        return;
    }
    NativeCmd nc;
    nc.cmd = L"drawTextAutoEllipsis";
    nc.colors.add(getPaintColor(dwPenColor));
    nc.texts.add(strText);
    nc.texts.add(FCTran::fontToStr(font));
    nc.rects.add(rect);
    m_commands.add(nc);
}

void AndroidPaint::endExport(){
}

void AndroidPaint::endPaint(){
    if(m_isClip){
        m_isClip = false;
    }
    //CGContextDrawImage(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, width, height), m_imageRef);
    //m_context = 0;
    //BitBlt(m_wndHDC, left, top, width, height, m_hDC, left, top, SRCCOPY);
    m_offsetX = 0;
    m_offsetY = 0;
}

void AndroidPaint::excludeClipPath(){
    NativeCmd nc;
    nc.cmd = L"excludeClipPath";
    m_commands.add(nc);
}

void AndroidPaint::fillEllipse(Long dwPenColor, const FCRect& rect){
    if(dwPenColor == FCColor_None){
        return;
    }
    NativeCmd nc;
    nc.cmd = L"fillEllipse";
    nc.colors.add(getPaintColor(dwPenColor));
    nc.rects.add(rect);
    m_commands.add(nc);
}

void AndroidPaint::fillGradientEllipse(Long dwFirst, Long dwSecond, const FCRect& rect, int angle){
    if(dwFirst == FCColor_None && dwSecond == FCColor_None){
        return;
    }
    NativeCmd nc;
    nc.cmd = L"fillGradientEllipse";
    nc.colors.add(getPaintColor(dwFirst));
    nc.colors.add(getPaintColor(dwSecond));
    nc.rects.add(rect);
    nc.values.add(angle);
    m_commands.add(nc);
}

void AndroidPaint::fillGradientPath(Long dwFirst, Long dwSecond, const FCRect& rect, int angle){
    if(dwFirst == FCColor_None && dwSecond == FCColor_None){
        return;
    }
    NativeCmd nc;
    nc.cmd = L"fillGradientPath";
    nc.colors.add(getPaintColor(dwFirst));
    nc.colors.add(getPaintColor(dwSecond));
    nc.rects.add(rect);
    nc.values.add(angle);
    m_commands.add(nc);
}

void AndroidPaint::fillGradientPolygon(Long dwFirst, Long dwSecond, FCPoint *apt, int cpt, int direction){
    if(dwFirst == FCColor_None && dwSecond == FCColor_None){
        return;
    }
    NativeCmd nc;
    nc.cmd = L"fillGradientPolygon";
    nc.colors.add(getPaintColor(dwFirst));
    nc.colors.add(getPaintColor(dwSecond));
    for(int i = 0; i < cpt; i++){
        nc.points.add(apt[i]);
    }
    nc.values.add(direction);
    m_commands.add(nc);
}

void AndroidPaint::fillGradientRect(Long dwFirst, Long dwSecond, const FCRect& rect, int cornerRadius, int angle){
    if(dwFirst == FCColor_None && dwSecond == FCColor_None){
        return;
    }
    NativeCmd nc;
    nc.cmd = L"fillGradientRect";
    nc.colors.add(getPaintColor(dwFirst));
    nc.colors.add(getPaintColor(dwSecond));
    nc.rects.add(rect);
    nc.values.add(cornerRadius);
    nc.values.add(angle);
    m_commands.add(nc);
}

void AndroidPaint::fillPath(Long dwPenColor){
    if(dwPenColor == FCColor_None){
        return;
    }
    NativeCmd nc;
    nc.cmd = L"fillPath";
    nc.colors.add(getPaintColor(dwPenColor));
    m_commands.add(nc);
}

void AndroidPaint::fillPie(Long dwPenColor, const FCRect& rect, float startAngle, float sweepAngle){
    if(dwPenColor == FCColor_None){
        return;
    }
    NativeCmd nc;
    nc.cmd = L"fillPie";
    nc.colors.add(getPaintColor(dwPenColor));
    nc.rects.add(rect);
    nc.values.add(startAngle);
    nc.values.add(sweepAngle);
    m_commands.add(nc);
}

void AndroidPaint::fillPolygon(Long dwPenColor, FCPoint *apt, int cpt){
    if(dwPenColor == FCColor_None){
        return;
    }
    NativeCmd nc;
    nc.cmd = L"fillPolygon";
    nc.colors.add(getPaintColor(dwPenColor));
    for(int i = 0; i < cpt; i++){
        nc.points.add(apt[i]);
    }
    m_commands.add(nc);
}

void AndroidPaint::fillRect(Long dwPenColor, const FCRect& rect){
    if(dwPenColor == FCColor_None){
        return;
    }
    NativeCmd nc;
    nc.cmd = L"fillRect";
    nc.colors.add(getPaintColor(dwPenColor));
    nc.rects.add(rect);
    m_commands.add(nc);
}

void AndroidPaint::fillRect(Long dwPenColor, int left, int top, int right, int bottom){
    if(dwPenColor == FCColor_None){
        return;
    }
    FCRect newRect = {left, top, right, bottom};
    fillRect(dwPenColor, newRect);
}

void AndroidPaint::fillRoundRect(Long dwPenColor, const FCRect& rect, int cornerRadius){
    if(dwPenColor == FCColor_None){
        return;
    }
    NativeCmd nc;
    nc.cmd = L"fillRoundRect";
    nc.colors.add(getPaintColor(dwPenColor));
    Long newColor = getPaintColor(dwPenColor);
    if(newColor < 0){
        int a = 0;
        int b = 0;
    }
    nc.rects.add(rect);
    nc.values.add(cornerRadius);
    m_commands.add(nc);
}

Long AndroidPaint::getColor(Long dwPenColor){
    return m_myColor->getUserColor(dwPenColor);
}

Long AndroidPaint::getPaintColor(Long dwPenColor){
    return getColor(dwPenColor);
}

FCPoint AndroidPaint::getOffset(){
    FCPoint offset = {m_offsetX, m_offsetY};
    return offset;
}

void AndroidPaint::getScaleFactor(double *scaleFactorX, double *scaleFactorY){
    *scaleFactorX = m_scaleFactorX;
    *scaleFactorY = m_scaleFactorY;
}

FCPoint AndroidPaint::rotate(const FCPoint& op, const FCPoint& mp, int angle){
    float PI = 3.14159265f;
    FCPoint pt = {0};
    pt.x = (int)((mp.x - op.x) * cos(angle * PI / 180) - (mp.y - op.y) * sin(angle * PI / 180) + op.x);
    pt.y = (int)((mp.x - op.x) * sin(angle * PI / 180) + (mp.y - op.y) * cos(angle * PI / 180) + op.y);
    return pt;
}

void AndroidPaint::setClip(const FCRect& rect){
    m_clipRect = rect;
    m_isClip = true;
    NativeCmd nc;
    nc.cmd = L"setClip";
    nc.rects.add(rect);
    m_commands.add(nc);

}

void AndroidPaint::setLineCap(int startLineCap, int endLineCap){
    NativeCmd pc;
    pc.cmd = L"setLineCap";
    pc.values.add(startLineCap);
    pc.values.add(endLineCap);
    m_commands.add(pc);
}

void AndroidPaint::setOffset(const FCPoint& offset){
    m_offsetX = offset.x;
    m_offsetY = offset.y;
    NativeCmd pc;
    pc.cmd = L"setOffset";
    pc.values.add(offset.x);
    pc.values.add(offset.y);
    m_commands.add(pc);
}

void AndroidPaint::setOpacity(float opacity){
    m_opacity = opacity;
    NativeCmd pc;
    pc.cmd = L"setOpacity";
    pc.values.add(opacity);
    m_commands.add(pc);
}

void AndroidPaint::setResourcePath(const String& resourcePath){
    NativeCmd pc;
    pc.cmd = L"setResourcePath";
    pc.texts.add(resourcePath);
    m_commands.add(pc);
}

void AndroidPaint::setRotateAngle(int rotateAngle){
    NativeCmd pc;
    pc.cmd = L"setRotateAngle";
    pc.values.add(rotateAngle);
    m_commands.add(pc);
}

void AndroidPaint::setScaleFactor(double scaleFactorX, double scaleFactorY){
    m_scaleFactorX = scaleFactorX;
    m_scaleFactorY = scaleFactorY;
    NativeCmd pc;
    pc.cmd = L"setScaleFactor";
    pc.values.add(scaleFactorX);
    pc.values.add(scaleFactorY);
    m_commands.add(pc);
}

bool AndroidPaint::supportTransparent(){
    return true;
}

FCSize AndroidPaint::textSize(String strText, FCFont *font, int width){
    AndroidHost *host = (AndroidHost*)m_native->getHost();
    jclass mainClass = host->m_env->FindClass("topin/facecat/MainActivity");
    jmethodID textSizeID = host->m_env->GetStaticMethodID(mainClass, "textSize", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)Ljava/lang/String;");
    jstring jCmd = host->m_env->NewStringUTF(FCTran::StringTostring(host->m_cppName).c_str());
    jstring jtext = host->m_env->NewStringUTF(FCTran::StringTostring(strText).c_str());
    jstring jfont = host->m_env->NewStringUTF(FCTran::StringTostring(FCTran::fontToStr(font)).c_str());
    jstring resStr = (jstring)host->m_env->CallStaticObjectMethod(mainClass, textSizeID, jCmd, jtext, jfont, width);
    char strCmd[1024] = {0};
    if(host->m_env->GetStringUTFLength(resStr) > 0){
        AndroidHost::JstringToString(strCmd, host->m_env, resStr);
    }
    String str = FCTran::stringToString(strCmd);
    return FCTran::strToSize(str);
}

FCSizeF AndroidPaint::textSizeF(String strText, FCFont *font, int width){
    AndroidHost *host = (AndroidHost*)m_native->getHost();
    jclass mainClass = host->m_env->FindClass("topin/facecat/MainActivity");
    jmethodID textSizeID = host->m_env->GetStaticMethodID(mainClass, "textSizeF", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)Ljava/lang/String;");
    jstring jCmd = host->m_env->NewStringUTF(FCTran::StringTostring(host->m_cppName).c_str());
    jstring jtext = host->m_env->NewStringUTF(FCTran::StringTostring(strText).c_str());
    jstring jfont = host->m_env->NewStringUTF(FCTran::StringTostring(FCTran::fontToStr(font)).c_str());
    jstring resStr = (jstring)host->m_env->CallStaticObjectMethod(mainClass, textSizeID, jCmd, jtext, jfont, width);
    char strCmd[1024] = {0};
    if(host->m_env->GetStringUTFLength(resStr) > 0){
        AndroidHost::JstringToString(strCmd, host->m_env, resStr);
    }
    String str = FCTran::stringToString(strCmd);
    ArrayList<String> strs = FCTran::split(str, L",");
    FCSizeF sizeF = {FCTran::strToFloat(strs.get(0)), FCTran::strToFloat(strs.get(1))};
    return sizeF;
}
